package com.example.mark.controller;

import com.example.mark.common.Result;
import com.example.mark.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/topic")
public class TopicController {

    @Autowired
    private TopicService topicService;

    @GetMapping("/list")
    public Result getTopicList() {
        return topicService.getTopicList();
    }

    @GetMapping("/hotList")
    public Result getHotTopicList() {
        return topicService.getHotTopicList();
    }

    @PostMapping("/publish")
    public Result publishTopic(@RequestBody Map<String, Object> requestParams) {
        return topicService.publishTopic(requestParams);
    }

    @PostMapping("/update")
    public Result updateTopic(@RequestBody Map<String, Object> requestParams) {
        return topicService.updateTopic(requestParams);
    }

    @PostMapping("/delete")
    public Result deleteTopic(@RequestBody Map<String, Object> requestParams) {
        int topicId = (int) requestParams.get("topicId");
        return topicService.deleteTopic(topicId);
    }

    @PostMapping("/upload")
    public Result uploadPhoto(@RequestParam("file") MultipartFile file) {
        return topicService.uploadTopicPhoto(file);
    }

    @GetMapping("/detail")
    public Result getTopicDetail(@RequestBody Map<String, Object> requestParams) {
        int topicId = (int) requestParams.get("topicId");
        return topicService.getTopicDetail(topicId);
    }
}
